package m1;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 本类用于
 *
 * @author SJXQ
 * @version 2022/1/21 14:14
 */
public class Consumer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("192.168.64.140");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("admin");
        connectionFactory.setPassword("admin");

        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();

        String queueName = "zipkin";
        channel.queueDeclare(queueName,true,false,false,null);

        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println("accept:" + new String(message.getBody()));
        };
        CancelCallback cancelCallback = consumerTag -> {};

        channel.basicConsume(queueName, true, deliverCallback, cancelCallback);
    }

}
